//@dart=2.12
import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/abnormal_event_center/response/abnormal_event_list_data.dart';

import 'abnormal_event_api.dart';

class AbnormalEventCenterModel extends BaseMvvmModel {
  @override
  void onCleared() {}

  Future<Map> abnormalStatistics() async {
    var data = await HttpGo.instance.postData(
      AbnormalEventApi.topStatistics,
    );
    if ("0" == data['code']) {
      return data['data'];
    } else {
      throw data['msg'];
    }
  }

  ///异常事件列表
  Future<List<AbnormalEventListData>> abnormalEventList(
      {String? bedNoLike,
      dynamic buildingId,
      String? elderNameLike,
      String? eventClass,
      int page = 1,
      int rows = 20,
      dynamic status}) async {
    var map = {
      "bedNoLike":bedNoLike,
      "buildingId":buildingId,
      "elderNameLike":elderNameLike,
      "eventClass":eventClass,
      "page":page,
      "rows":rows,
      "status":status,
    };
    var data = await HttpGo.instance.postData(AbnormalEventApi.abnormalEventList,data: map,options: Options(contentType: Headers.jsonContentType));
    if("0"==data['code']){
      return ((data['data']['rows'] as List?)??[]).map((e) => AbnormalEventListData.fromJson(e)).toList();
    }else{
      throw data['msg'];
    }
  }

  ///关闭
  Future<Map> closeEvent(dynamic id) async {
    var map = {
      "id":id
    };
    var data = await HttpGo.instance.postData(AbnormalEventApi.closeEvent,data: map,options: Options(contentType: Headers.formUrlEncodedContentType));
    if("0"==data['code']){
      return data;
    }else{
      throw data['msg'];
    }
  }
}
